# 每一次请求都会调用
from flask import request, render_template


REQUEST_COUNT = {}

def set_after_request_handle_fuc(app):

    @app.before_request
    def before_request():
        ip = request.remote_addr

        global REQUEST_COUNT

        if ip in REQUEST_COUNT:
            REQUEST_COUNT[ip] += 1
        else:
            REQUEST_COUNT[ip] = 1



    @app.errorhandler(500)
    def internal_server_500(e):
        return "服务器搬家了"


    @app.errorhandler(404)
    def internal_server_404(e):
        return render_template("public/404.html"), 404
